package com.design_mode;

/**
 * Created by dustaple on 8/3/14.
 */
public class MementoPattern {
    public static void main(String[] args){
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();
        caretaker.setMemento(originator.createMemento());
        originator.restore(caretaker.getMemento());
    }
}

class Originator {
    int state;

    public Memento createMemento() {
        return new Memento(state);
    }
    public void restore(Memento memento){
        this.state = memento.getState();
    }
    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }
}

class Memento {
    int state;

    public Memento(int state) {
        this.state = state;
    }

    int getState() {
        return state;
    }
}
class Caretaker{
    Memento memento;

    public Memento getMemento() {
        return memento;
    }

    public void setMemento(Memento memento) {
        this.memento = memento;
    }
}